package initialize

import (
	"fmt"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"models"
	"types"
)

type Mysql struct {
	User     string
	Pwd      string
	Host     string
	Port     int
	Database string
}

var (
	err error
)

func InitMysql() {
	App := Mysql{
		User:     "root",
		Pwd:      "123456",
		Host:     "1.94.42.54",
		Port:     3306,
		Database: "2204AA",
	}

	dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=True&loc=Local", App.User, App.Pwd, App.Host, App.Port, App.Database)
	types.Db, err = gorm.Open(mysql.Open(dsn))
	if err != nil {
		panic("Mysql数据库连接失败")
		return
	}
	fmt.Println("Mysql数据库连接成功")
	types.Db.AutoMigrate(new(models.User), new(models.Shop), new(models.ShopTime), new(models.Order))
	fmt.Println(dsn)
}
